﻿using System.Collections.Generic;
using Newtonsoft.Json;
using ZYing.LiquidThemeEngine.Config.Schemas;
using ZYing.LiquidThemeEngine.Locales;

namespace ZYing.LiquidThemeEngine.Config.Schemas;

public class ThemeSettingSchemaCollection : List<ThemeSettingSchema>
{
    public static ThemeSettingSchemaCollection Parse(string value)
    {
        return JsonConvert.DeserializeObject<ThemeSettingSchemaCollection>(value);
    }

    public LiquidThemeInfo GetThemeInfo()
    {
        foreach (var item in this)
        {
            if (item.Name is FixedLocalizableText { Text: "theme_info" } && item is ThemeSettingSchemaForThemeInfo info)
            {
                return new LiquidThemeInfo
                {
                    ThemeName = info.ThemeName,
                    ThemeAuthor = info.ThemeAuthor,
                    ThemeVersion = info.ThemeVersion,
                    ThemeDocumentationUrl = info.ThemeDocumentationUrl,
                    ThemeSupportEmail = info.ThemeSupportEmail,
                    ThemeSupportUrl = info.ThemeSupportUrl
                };
            }
        }
        return null;
    }
}